//
//  UIImageView+Extension.m
//  FullShareTop
//
//  Created by lqq on 17/3/21.
//  Copyright © 2017年 FSB. All rights reserved.
//

#import "UIImageView+Extension.h"
#import <UIImageView+WebCache.h>

@implementation UIImageView (Extension)
/**
 根据颜色渲染图片
 */
- (void)setImageWithName:(NSString *)imageName renderingImageWithColor:(UIColor *)color
{
    UIImage *image = [UIImage imageNamed:imageName];
    self.image  =[image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    self.tintColor = color;
}

//加载头像
- (void)setAvaterImageWithUrl:(NSString *)url
{
//    self.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    __weak __typeof (self)weakSelf = self;
    self.contentMode = UIViewContentModeScaleAspectFill;
    [self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"ic_120_user"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        if (image) {
            weakSelf.image = image;
        }
    }];
}


//加载图片
- (void)setNetImageWithUrl:(NSString *)url
{
    self.layer.masksToBounds = YES;
    self.contentMode = UIViewContentModeScaleAspectFill;
//    self.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    __weak __typeof (self)weakSelf = self;
    [weakSelf sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"ic_120_mendian"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        if (image) {
            weakSelf.backgroundColor = [UIColor clearColor];
        }
    }];
}
@end
